////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017-2018 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxipenode.h
/// @brief IPENode class declarations
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXIPENODE_H
#define CAMXIPENODE_H

#include "camxcmdbuffermanager.h"
#include "camxcslicpdefs.h"
#include "camxhwcontext.h"
#include "camxispiqmodule.h"
#include "camxmem.h"
#include "camxnode.h"
#include "chipinforeaderdefs.h"
#include "ipeStripingLib.h"
#include "ipe_data.h"

CAMX_NAMESPACE_BEGIN

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_FULL) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdFull));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS4) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS4));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS16) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS16));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS64) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS64));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_FULL_REF) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdFullRef));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS4_REF) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS4Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS16_REF) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS16Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_INPUT_IMAGE_DS64_REF) ==
    static_cast<UINT32>(CSLIPEInputPortId::CSLIPEInputPortIdDS64Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_DISPLAY) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdDisplay));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_VIDEO) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdVideo));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_FULL_REF) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdFullRef));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_DS4_REF) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdDS4Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_DS16_REF) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdDS16Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_OUTPUT_IMAGE_DS64_REF) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdDS64Ref));

CAMX_STATIC_ASSERT(static_cast<UINT32>(IPE_IO_IMAGES::IPE_IO_IMAGES_MAX) ==
    static_cast<UINT32>(CSLIPEOutputPortId::CSLIPEOutputPortIdMaxNumPortResources));

static const UINT ICA_MODE_DISABLED     = 0;    ///< IPE ICA mode disabled
static const UINT ICA_MODE_ENABLED      = 1;    ///< IPE ICA mode enabled
static const UINT ICA_MODE_MAX          = 2;    ///< IPE ICA mode max

static const UINT UBWC_MODE_DISABLED    = 0;    ///< IPE UBWC mode disabled
static const UINT UBWC_MODE_ENABLED     = 1;    ///< IPE UBWC mode enabled
static const UINT UBWC_MODE_MAX         = 2;    ///< IPE UBWC mode max

static const UINT32 ICAMinWidthPixels  = 30;
static const UINT32 ICAMinHeightPixels = 26;
static const UINT32 BPSMinWidthPixels  = 64;
static const UINT32 BPSMinHeightPixels = 64;

/// @brief IPE IQ Module Information
struct IPEIQModuleInfo
{
    ISPIQModuleType   moduleType;                                   ///< IQ Module Type
    BOOL              isEnabled;                                    ///< Module Available or not
    IPEPath           path;                                         ///< IPE path indicating if it is input or reference
    CamxResult        (*IQCreate)(IPEModuleCreateData* pInputData); ///< Static create fuction of this IQ Module
};

/// @brief IPE Stats Vendor Tag Id
enum IPEStatsVendorTagId
{
    IPEVendorTagAECStats = 0,       ///< Vendor Tag for AEC stats
    IPEVendorTagAWBStats,           ///< Vendor Tag for AWB stats
    IPEVendorTagAFStats,            ///< Vendor Tag for AF stats
    IPEVendorTagAECFrame,           ///< Vendor Tag for AEC frame
    IPEVendorTagAWBFrame,           ///< Vendor Tag for AWB frame
    IPEVendorTagMax                 ///< Max number of Vendor Tag
};

/// @brief IPE IQ Vendor Tag Id
enum IPEIQVendorTagId
{
    IPEIQParam,         ///< Vendor Tag for IQ Param
    IPEIQVendorTagMax   ///< Max number of Vendor Tag
};

/// @brief IPE Image Information
struct IPEImageInfo
{
    UINT  width;               ///< Width of the image
    UINT  height;              ///< Height of the image
    FLOAT bpp;                 ///< bpp
    BOOL  UBWCEnable;          ///< UBWC Flag
};

/// @brief IPE Bandwidth Information
struct IPEBandwidthSource
{
    UINT64 compressedBW;        ///< compressed bandwidth
    UINT64 unCompressedBW;      ///< unCompressed bandwidth
};

/// @brief IPE Total Bandwidth
struct IPEBandwidth
{
    IPEBandwidthSource readBW;            ///< read Bandwidth
    IPEBandwidthSource writeBW;           ///< write Bandwidth
    UINT               FPS;               ///< FPS
    FLOAT              partialBW;         ///< partial Bandwidth
};

/// @brief IPE Capability Information
struct IPECapabilityInfo
{
    UINT             numIPEIQModules;              ///< Number of IQ Modules
    IPEIQModuleInfo* pIPEIQModuleList;             ///< List of IQ Module
    UINT             numIPE;                       ///< Number of IPE
    BOOL             swStriping;                   ///< Striping done in UMD
    UINT             maxInputWidth[ICA_MODE_MAX];  ///< Max IPE input  width
    UINT             maxInputHeight[ICA_MODE_MAX]; ///< Max IPE input  height
    UINT             maxOutputWidth;               ///< Max IPE output width
    UINT             maxOutputHeight;              ///< Max IPE output height
    UINT             minInputWidth;                ///< Min IPE input  width
    UINT             minInputHeight;               ///< Min IPE input  height
    UINT             minOutputWidth;               ///< Min IPE output width
    UINT             minOutputHeight;              ///< Min IPE output width
    FLOAT            maxUpscale[UBWC_MODE_MAX];    ///< Max upscale limit
    FLOAT            maxDownscale[UBWC_MODE_MAX];  ///< Max downscale limit
    UINT             minOutputWidthUBWC;           ///< Min IPE output width for UBWC
    UINT             minOutputHeightUBWC;          ///< Min IPE output height for UBWC
};

/// @brief IPE updates to metadata
static const UINT IPEMetadataOutputTags[] =
{
    ControlMode,
    ControlEffectMode,
    ControlSceneMode,
    EdgeMode,
    ControlVideoStabilizationMode,
    ColorCorrectionAberrationMode,
    NoiseReductionMode,
    TonemapMode,
    ColorCorrectionMode,
    ColorCorrectionTransform,
    TonemapCurveBlue,
    TonemapCurveGreen,
    TonemapCurveRed,
};

static const UINT NumIPEMetadataOutputTags = sizeof(IPEMetadataOutputTags) / sizeof(UINT32);  ///< Number of output vendor tags

static const UINT IPEMaxSupportedBatchSize = MAX_HFR_GROUP; ///< Max batch size by firmware

/// @brief IPE Properties for ICA
static const UINT IPEProperties = 9;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Class that implements the IPE node class
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class IPENode final : public Node
{
public:
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// Create
    ///
    /// @brief  Static method to create IPENode Object.
    ///
    /// @param  pCreateInputData  Node create input data
    /// @param  pCreateOutputData Node create output data
    ///
    /// @return Pointer to the concrete IPENode object
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static IPENode* Create(
        const NodeCreateInputData* pCreateInputData,
        NodeCreateOutputData*      pCreateOutputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// Destroy
    ///
    /// @brief  This method destroys the derived instance of the interface
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual VOID Destroy();

protected:
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ProcessingNodeInitialize
    ///
    /// @brief  Initialize the hwl object
    ///
    /// @param  pCreateInputData  Node create input data
    /// @param  pCreateOutputData Node create output data
    ///
    /// @return CamxResultSuccess if successful
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual CamxResult ProcessingNodeInitialize(
        const NodeCreateInputData* pCreateInputData,
        NodeCreateOutputData*      pCreateOutputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// PostPipelineCreate
    ///
    /// @brief  virtual method to be called at NotifyTopologyCreated time; node should take care of updates and initialize
    ///         blocks that has dependency on other nodes in the topology at this time.
    ///
    /// @return CamxResultSuccess if successful
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual CamxResult PostPipelineCreate();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ExecuteProcessRequest
    ///
    /// @brief  Pure virtual method to trigger process request for the hwl node object.
    ///
    /// @param  pExecuteProcessRequestData Process request data
    ///
    /// @return CamxResultSuccess if successful and 0 dependencies, dependency information otherwise
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual CamxResult ExecuteProcessRequest(
        ExecuteProcessRequestData* pExecuteProcessRequestData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ProcessingNodeFinalizeInputRequirement
    ///
    /// @brief  Virtual method implemented by IPE node to determine its input buffer requirements based on all the output
    ///         buffer requirements
    ///
    /// @param  pBufferNegotiationData  Negotiation data for all output ports of a node
    ///
    /// @return Success if the negotiation was successful, Failure otherwise
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual CamxResult ProcessingNodeFinalizeInputRequirement(
        BufferNegotiationData* pBufferNegotiationData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CalculateInputWithoutMargins
    ///
    /// @brief  TO get the margins which are not published before FinalizeBufferProperties
    ///
    /// @param  pWidth                  Input width
    /// @param  pHeight                 Input Height
    ///
    /// @return Success if margin was calculated
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult CalculateInputWithoutMargins(
        UINT* pWidth,
        UINT* pHeight);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FinalizeBufferProperties
    ///
    /// @brief  Finalize the buffer properties of each output port
    ///
    /// @param  pBufferNegotiationData Buffer negotiation data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual VOID FinalizeBufferProperties(
        BufferNegotiationData* pBufferNegotiationData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ~IPENode
    ///
    /// @brief  Destructor
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual ~IPENode();

private:
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IPENode
    ///
    /// @brief  Constructor
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    IPENode();
    IPENode(const IPENode&) = delete;                 ///< Disallow the copy constructor.
    IPENode& operator=(const IPENode&) = delete;      ///< Disallow assignment operator.

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetupDeviceResource
    ///
    /// @brief  Setup List of the Required Resource
    ///
    /// @param  pConfigIOMem    Pointer to shared memory allocated buffer
    /// @param  pResource       Pointer to an arry of resource
    ///
    /// @return CamxResult      CamxResultSucess when sucessful
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult SetupDeviceResource(
        CSLBufferInfo*     pConfigIOMem,
        CSLDeviceResource* pResource);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// TranslateToFirmwarePortId
    ///
    /// @brief     Helper method to find the firmware port id
    ///
    /// @param     portId             Input port id
    /// @param     pFirmwarePortId    pointer holding the firmware port id
    ///
    /// @return    None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID TranslateToFirmwarePortId(
        UINT32         portId,
        IPE_IO_IMAGES* pFirmwarePortId);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// AcquireDevice
    ///
    /// @brief  Helper method to acquire IPE device
    ///
    /// @return CamxResultSuccess
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult AcquireDevice();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ReleaseDevice
    ///
    /// @brief  Helper method to release IPE device
    ///
    /// @return CamxResultSuccess
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult ReleaseDevice();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ConfigureIPECapability
    ///
    /// @brief  Set up IPE capability based on IPE revision number
    ///
    /// @return CamxResultSuccess
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult ConfigureIPECapability();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // UpdateIPEIOLimits
    ///
    /// @brief  Update IPE buffer negotiation data based on the the ports enabled
    ///
    /// @param  pBufferNegotiationData        Buffer negotiation data containing the port info.
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult UpdateIPEIOLimits(
       BufferNegotiationData* pBufferNegotiationData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CreateIPEIQModules
    ///
    /// @brief  Create IQ Modules of the IPE Block
    ///
    /// @return CamxResultSuccess
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult CreateIPEIQModules();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// PopulateGeneralTuningMetadata
    ///
    /// @brief  Helper to populate tuning data easily obtain at IPE node level
    ///
    /// @param  pInputData Pointer to the data input and output stuctures are inside
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID PopulateGeneralTuningMetadata(
        ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// DumpTuningMetadata
    ///
    /// @brief  Helper to publish tuning metadata
    ///
    /// @param  pInputData Pointer to the input data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID DumpTuningMetadata(
        ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// PostMetadata
    ///
    /// @brief  Post IPE metadata to main metadata pool
    ///
    /// @param  pInputData Pointer to the input data
    ///
    /// @return CamxResultSuccess if successful.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult PostMetadata(
        const ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ProgramIQConfig
    ///
    /// @brief  Reprogram the settings for the IQ Modules
    ///
    /// @param  pInputData Pointer to the input data
    ///
    /// @return CamxResultSuccess
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult ProgramIQConfig(
        ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetMetadataTags
    ///
    /// @brief  Get all information from HAL metadata tags for all IPE modules
    ///
    /// @param  pModuleInput Pointer to the input and output data
    ///
    /// @return CamxResultSuccess if successful.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetMetadataTags(
        ISPInputData* pModuleInput);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetIQModuleNumLUT
    ///
    /// @brief  Store number of Look Up Tables to be written for every IQ modules
    ///
    /// @param  type        IQ module type
    /// @param  numLUTs     Number of look up tables present in IQ module
    /// @param  path        path variable representing IPE path type
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void SetIQModuleNumLUT(
        ISPIQModuleType type,
        UINT            numLUTs,
        INT             path);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// UpdateIQCmdSize
    ///
    /// @brief  Calculate Maximum Command Buffer size required for all the available IQ Modules
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void UpdateIQCmdSize();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// Cleanup
    ///
    /// @brief  Clean up the allocated IQ modules and Stats Modules
    ///
    /// @return CamxResultSuccess if success
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult Cleanup();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// NotifyRequestProcessingError
    ///
    /// @brief  Function that does any error processing required for a fence callback. When CSL notifies the Node of a fence we
    ///         post a job in the threadpool. And when threadpool calls us to process the error fence-signal notification, this
    ///         function does the necessary processing.
    ///
    /// @param  pFenceHandlerData Pointer to struct FenceHandlerData that belongs to this node
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    virtual VOID NotifyRequestProcessingError(
            NodeFenceHandlerData* pFenceHandlerData);



    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetDependencies
    ///
    /// @brief  Check the availability of the dependence data. Update the data if it is available
    ///
    /// @param  pNodeRequestData           Pointer to the incoming NodeProcessRequestData
    /// @param  parentNodeId               Parent node id for this request
    /// @param  allOutputPortsAreLoopback  Flag to indicate if all output ports are loopback
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID SetDependencies(
        NodeProcessRequestData*  pNodeRequestData,
        UINT                     parentNodeId,
        BOOL                     allOutputPortsAreLoopback);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetICADependencies
    ///
    /// @brief  Check the availability of the dependence data. Update the data if it is available
    ///
    /// @param  pNodeRequestData           Pointer to the incoming NodeProcessRequestData
    /// @param  allOutputPortsAreLoopback  Flag to indicate if all output ports are loopback
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID SetICADependencies(
        NodeProcessRequestData*  pNodeRequestData,
        BOOL                     allOutputPortsAreLoopback);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetGammaOutput
    ///
    /// @brief  Get gamma output for programming IPE IQ
    ///
    /// @param  pISPData   ISP Internal data to be set from metadata
    /// @param  parentID   Parent node ID
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetGammaOutput(
        ISPInternalData* pISPData,
        UINT32           parentID);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetADRCDependencies
    ///
    /// @brief  Set ADRC Dependency
    ///
    /// @param  pNodeRequestData Pointer to the incoming NodeProcessRequestData
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID SetADRCDependencies(
            NodeProcessRequestData* pNodeRequestData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetADRCInfoOutput
    ///
    /// @brief  Get ADRC output for programming IPE IQ
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetADRCInfoOutput();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillIQSetting
    ///
    /// @brief  Fill IPE IQ settings
    ///
    /// @param  pInputData          Pointer to ISP Input Data
    /// @param  pIPEIQsettings      IQSettings payload for firmware
    /// @param  pPerRequestPorts    Pointer to per request active ports
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillIQSetting(
        ISPInputData*            pInputData,
        IpeIQSettings*           pIPEIQsettings,
        PerRequestActivePorts*   pPerRequestPorts);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillFramePerfParams
    ///
    /// @brief  Find the OutputChannel based on the port number
    ///
    /// @param  pFrameProcessData   Top level payload for firmware
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillFramePerfParams(
        IpeFrameProcessData* pFrameProcessData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillFrameUBWCParams
    ///
    /// @brief  Find the OutputChannel based on the port number
    ///
    /// @param  pFrameProcessData   Top level payload for firmware
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillFrameUBWCParams(
        IpeFrameProcessData* pFrameProcessData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillFrameZoomWindow
    ///
    /// @brief  Fill the zoom window for a frame
    ///
    /// @param  pInputData       pointer to ISP input data
    /// @param  parentNodeId     Parent node id for this request
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillFrameZoomWindow(
        ISPInputData*     pInputData,
        UINT              parentNodeId);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillFrameBufferData
    ///
    /// @brief  Populate Frame buffer structure in firmware payload
    ///
    /// @param  pMainCmdBuffer              Pointer to top level firmware payload command buffer
    /// @param  pImageBuffer                Image buffer that needs to be attached to payload
    /// @param  payloadPatchedFrameIndex    In HFR mode this field indicates which frame within batch in payload
    /// @param  bufferPatchedFrameIndex     In HFR mode this field indicates which frame within batch in buffer
    /// @param  portId                      Port Id at which buffer should be assigned
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillFrameBufferData(
        CmdBuffer*      pMainCmdBuffer,
        ImageBuffer*    pImageBuffer,
        UINT32          payloadPatchedFrameIndex,
        UINT32          bufferPatchedFrameIndex,
        UINT32          portId);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillInputFrameSetData
    ///
    /// @brief  Fill the frame data for all input ports/buffers , cosider batch size as well for HFR mode
    ///
    /// @param  pFrameProcessCmdBuffer  Pointer to top level firmware payload command buffer
    /// @param  portId                  Input or output port id
    /// @param  pImageBuffer            Image buffer associated with the port
    /// @param  numFramesInBuffer       Either 1 or usecase number of frames in a batch
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillInputFrameSetData(
        CmdBuffer*      pFrameProcessCmdBuffer,
        UINT            portId,
        ImageBuffer*    pImageBuffer,
        UINT32          numFramesInBuffer);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillInputFrameSetDataForBatchReferencePorts
    ///
    /// @brief  Fill the frame data for all input ports/buffers , cosider batch size as well for HFR mode
    ///
    /// @param  pFrameProcessCmdBuffer  Pointer to top level firmware payload command buffer
    /// @param  portId                  Input or output port id
    /// @param  pImageBufferPrevious    Image buffer associated with the port's previous request's buffer
    /// @param  pImageBufferCurrent     Image buffer associated with the port's currents request's buffer
    /// @param  numFramesInBuffer       Either 1 or usecase number of frames in a batch
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillInputFrameSetDataForBatchReferencePorts(
        CmdBuffer*      pFrameProcessCmdBuffer,
        UINT            portId,
        ImageBuffer*    pImageBufferPrevious,
        ImageBuffer*    pImageBufferCurrent,
        UINT32          numFramesInBuffer);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillOutputFrameSetData
    ///
    /// @brief  Fill the frame data for all output ports/buffers, cosider batch size as well for HFR mode
    ///
    /// @param  pFrameProcessCmdBuffer  Pointer to top level firmware payload command buffer
    /// @param  portId                  Input or output port id
    /// @param  pImageBuffer            Image buffer associated with the port
    /// @param  batchedFrameIndex       Buffer index within batch
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillOutputFrameSetData(
        CmdBuffer*              pFrameProcessCmdBuffer,
        UINT                    portId,
        ImageBuffer*            pImageBuffer,
        UINT32                  batchedFrameIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillPreLTMCDMProgram
    ///
    /// @brief  Fill the frame data for all ports, cosider batch size as well for HFR mode
    ///
    /// @param  ppIPECmdBuffer      Pointer to array of command buffers for given frame
    /// @param  pCdmProgramArray    Pointer to array of CDMProgramArray
    /// @param  pCdmProgram         Pointer to CdmProgram to be configured
    /// @param  programType         Program type of CDM Program defined by firmware interface
    /// @param  programIndex        Program index which determines order of CdmProgram
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillPreLTMCDMProgram(
        CmdBuffer**             ppIPECmdBuffer,
        CDMProgramArray*        pCdmProgramArray,
        CdmProgram*             pCdmProgram,
        ProgramType             programType,
        PreLTMCDMProgramOrder   programIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillPostLTMCDMProgram
    ///
    /// @brief  Fill the frame data for all ports, cosider batch size as well for HFR mode
    ///
    /// @param  ppIPECmdBuffer      Pointer to array of command buffers for given frame
    /// @param  pCdmProgramArray    Pointer to array of CDMProgramArray
    /// @param  pCdmProgram         Pointer to CdmProgram to be configured
    /// @param  programType         Program type of CDM Program defined by firmware interface
    /// @param  programIndex        Program index which determines order of CdmProgram
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillPostLTMCDMProgram(
        CmdBuffer**             ppIPECmdBuffer,
        CDMProgramArray*        pCdmProgramArray,
        CdmProgram*             pCdmProgram,
        ProgramType             programType,
        PostLTMCDMProgramOrder  programIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillNPSCDMProgram
    ///
    /// @brief  Fill the frame data for all ports, cosider batch size as well for HFR mode
    ///
    /// @param  ppIPECmdBuffer      Pointer to array of command buffers for given frame
    /// @param  pCdmProgramArray    Pointer to array of CDMProgramArray
    /// @param  pCdmProgram         Pointer to CdmProgram to be configured
    /// @param  programType         Program type of CDM Pgoram defined by firmware interface
    /// @param  arrayIndex          Index  of cdm buffer in main payload
    /// @param  passCmdBufferSize   Size of cmd buffer size
    /// @param  passOffset          Offset of the pass of CdmProgram
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillNPSCDMProgram(
        CmdBuffer**             ppIPECmdBuffer,
        CDMProgramArray*        pCdmProgramArray,
        CdmProgram*             pCdmProgram,
        ProgramType             programType,
        CDMProgramArrayOrder    arrayIndex,
        UINT32                  passCmdBufferSize,
        UINT32                  passOffset);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillICACDMprograms
    ///
    /// @brief  Fill the frame data for all ports, cosider batch size as well for HFR mode
    ///
    /// @param  pFrameProcessData   Frame process data
    /// @param  ppIPECmdBuffer      Pointer to array of command buffers for given frame
    /// @param  programType         Program type of CDM Pgoram defined by firmware interface
    /// @param  programArrayOrder   Index  of cdm buffer in main payload
    /// @param  programIndex        Index for ICA program
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    CamxResult FillICACDMprograms(
        IpeFrameProcessData*    pFrameProcessData,
        CmdBuffer**             ppIPECmdBuffer,
        ProgramType             programType,
        CDMProgramArrayOrder    programArrayOrder,
        ICAProgramOrder         programIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillCDMProgramArrays
    ///
    /// @brief  Fill the frame data for all ports, cosider batch size as well for HFR mode
    ///
    /// @param  pFrameProcessData  Pointer to top level firmware payload data structure
    /// @param  pIpeIQSettings     IQ Settings pointer
    /// @param  ppIPECmdBuffer     Pointer to array of different command buffers
    /// @param  batchFrames        Number of batached frames
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillCDMProgramArrays(
        IpeFrameProcessData*    pFrameProcessData,
        IpeIQSettings*          pIpeIQSettings,
        CmdBuffer**             ppIPECmdBuffer,
        UINT                    batchFrames);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // CommitAllCommandBuffers
    ///
    /// @brief  Find the OutputChannel based on the port number
    ///
    /// @param  ppIPECmdBuffer           Pointer array of all command buffers managed by IPE node
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult CommitAllCommandBuffers(
        CmdBuffer** ppIPECmdBuffer);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // GetCDMProgramArrayOffsetFromBase
    ///
    /// @brief  Calculate the offset in bytes, of the CDMProgram Array from base CDMProgramArray
    ///
    /// @param  arrayIndex  CDM Program array index (CDMProgramArrayOrder)
    ///
    /// @return return Offset of CDM program array from Base CDMProgramArray, -1 for failure
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static INT GetCDMProgramArrayOffsetFromBase(
        CDMProgramArrayOrder    arrayIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // GetCDMProgramArrayOffsetFromTop
    ///
    /// @brief  Calculate the offset in bytes, of the CDMProgram from start of IpeFrameProcess
    ///
    /// @param  arrayIndex     CDM Program index (CDMProgramArrayOrder)
    ///
    /// @return return Offset of CDM program array from start of IpeFrameProcess, -1 for failure
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static INT GetCDMProgramArrayOffsetFromTop(
        CDMProgramArrayOrder    arrayIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // GetCDMProgramOffset
    ///
    /// @brief  Calculate the offset in bytes, of the CDMProgram from start of IpeFrameProcess
    ///
    /// @param  arrayIndex      CDM Program Array index (CDMProgramArrayOrder)
    /// @param  cdmProgramIndex CDM Program index (PreLTMCDMProgramOrder or PostLTMCDMProgramOrder)
    ///
    /// @return return Offset of CDM program from start of IpeFrameProcess, -1 for failure
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static INT GetCDMProgramOffset(
        CDMProgramArrayOrder    arrayIndex,
        UINT                    cdmProgramIndex);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // InitializeStripingParams
    ///
    /// @brief  Initialize the striping library and create a command buffer
    ///
    /// @param  pConfigIOData  Ipe IO configuration data for firmware
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult InitializeStripingParams(
        IpeConfigIoData* pConfigIOData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FillStripingParams
    ///
    /// @brief  Get the striping params from striping library and fill the command buffer
    ///
    /// @param  pFrameProcessData             Top level payload for firmware
    /// @param  pIPEIQsettings                IQSettings payload for firmware
    /// @param  ppIPECmdBuffer                Pointer to array of all command buffers managed by IPE node
    /// @param  pICPClockBandwidthRequest     Pointer to Clock and Bandwidth request
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult FillStripingParams(
        IpeFrameProcessData*         pFrameProcessData,
        IpeIQSettings*               pIPEIQsettings,
        CmdBuffer**                  ppIPECmdBuffer,
        CSLICPClockBandwidthRequest* pICPClockBandwidthRequest);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // PatchBLMemoryBuffer
    ///
    /// @brief  patch the BL command buffer
    ///
    /// @param  pFrameProcessData             Top level payload for firmware
    /// @param  ppIPECmdBuffer                Pointer to array of all command buffers managed by IPE node
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult PatchBLMemoryBuffer(
        IpeFrameProcessData* pFrameProcessData,
        CmdBuffer**          ppIPECmdBuffer);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetAAAInputData
    ///
    /// @brief  Hook up the AEC/AWB settings for the IQ Modules
    ///
    /// @param  pInputData    Pointer to the ISP input data for AAA setting updates
    /// @param  parentNodeID  Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID SetAAAInputData(
        ISPInputData* pInputData,
        UINT          parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetFaceROI
    ///
    /// @brief  Returns FD ROI information
    ///
    /// @param  pInputData       Pointer to the input data
    /// @param  parentNodeID     Parent node id
    ///
    /// @return CamxResultSuccess if success
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetFaceROI(
        ISPInputData* pInputData,
        UINT          parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsIPEOnlyDownscalerEnabled
    ///
    /// @brief  Determine if IPE only downscaler is enabled
    ///
    /// @param  pBufferNegotiationData          Negotiation data for all output ports of a node
    ///
    /// @return return enabled/disabled
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL IsIPEOnlyDownscalerEnabled(
        BufferNegotiationData* pBufferNegotiationData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsFDEnabled
    ///
    /// @brief  Determine if FD is enabled
    ///
    ///
    /// @return return enabled/disabled
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL IsFDEnabled();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetIPEDownscalerOnlyDimensions
    ///
    /// @brief  Determine if IPE only downscaler is enabled
    ///
    /// @param  width               Width
    /// @param  height              Height
    /// @param  pMaxWidth           Maximum width for IPE only downscaler
    /// @param  pMaxHeight          Maximum height for IPE only downscaler
    /// @param  downscaleLimit      Downscale limit
    /// @param  downScalarMode      Mode
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID GetIPEDownscalerOnlyDimensions(
        UINT32  width,
        UINT32  height,
        UINT32* pMaxWidth,
        UINT32* pMaxHeight,
        FLOAT   downscaleLimit,
        UINT    downScalarMode);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsStandardAspectRatio
    ///
    /// @brief  Determine if the aspect ratio is one of the standard 1:1, 4:3, 16:9 or 18.5:9
    ///
    /// @param  aspectRatio Aspect Ratio of check against the standard aspect ratios
    ///
    /// @return return BOOL
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL IsStandardAspectRatio(
        FLOAT aspectRatio);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CheckDimensionRequirementsForIPEDownscaler
    ///
    /// @brief  Determine if IPE only downscaler is enabled
    ///
    /// @param  width               Width
    /// @param  height              Height
    /// @param  downScalarMode      Mode
    ///
    /// @return return BOOL
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL CheckDimensionRequirementsForIPEDownscaler(
        UINT32 width,
        UINT32 height,
        UINT   downScalarMode);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// HardcodeSettings
    ///
    /// @brief  Hardcode settings for the IPE IQ Modules
    ///
    /// @param  pInputData Pointer to the ISP input data for setting updates
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID HardcodeSettings(
        ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// UpdateICADependencies
    ///
    /// @brief  Update the ICA Input Data
    ///
    /// @param  pInputData    Pointer to the ISP input data for setting updates
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult UpdateICADependencies(
        ISPInputData* pInputData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// PublishICADependencies
    ///
    /// @brief  Publish ICA Input Data
    ///
    /// @param  pNodeRequestData    Pointer to the ISP input data for setting updates
    ///
    /// @return return CamxResult
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult PublishICADependencies(
        NodeProcessRequestData* pNodeRequestData);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// HardcodeAAAInputData
    ///
    /// @brief  Hardcode AAA Input Data for now
    ///
    /// @param  pInputData    Pointer to the ISP input data for setting updates
    /// @param  parentNodeID  Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID HardcodeAAAInputData(
        ISPInputData* pInputData,
        UINT          parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///  UpdateClock
    ///
    /// @brief  Update clock parameters in a command buffer
    ///
    /// @param  pICPClockBandwidthRequest       clock data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID UpdateClock(
        CSLICPClockBandwidthRequest* pICPClockBandwidthRequest);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  UpdateBandwidth
    ///
    /// @brief  Update Bandwidth parameters in a command buffer
    ///
    /// @param  pExecuteProcessRequestData Request specific data
    /// @param  pICPClockBandwidthRequest  Bandwidth data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID UpdateBandwidth(
        ExecuteProcessRequestData*   pExecuteProcessRequestData,
        CSLICPClockBandwidthRequest* pICPClockBandwidthRequest);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  CheckAndUpdateClockBW
    ///
    /// @brief  Update Bandwidth and Clock parameters in a command buffer
    ///
    /// @param  pCmdBuffer                 Command Buffer
    /// @param  pExecuteProcessRequestData Request specific data
    /// @param  pICPClockBandwidthRequest  Bandwidth data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID CheckAndUpdateClockBW(
        CmdBuffer*                   pCmdBuffer,
        ExecuteProcessRequestData*   pExecuteProcessRequestData,
        CSLICPClockBandwidthRequest* pICPClockBandwidthRequest);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  CalculateIPERdBandwidth
    ///
    /// @brief  Calculate Read Bandwidth
    ///
    /// @param  pPerRequestPorts Request specific data
    /// @param  pBandwidth       Bandwidth data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID CalculateIPERdBandwidth(
        PerRequestActivePorts*  pPerRequestPorts,
        IPEBandwidth*           pBandwidth);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  CalculateIPEWrBandwidth
    ///
    /// @brief  Calculate Write Bandwidth
    ///
    /// @param  pPerRequestPorts Request specific data
    /// @param  pBandwidth       Bandwidth data
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID CalculateIPEWrBandwidth(
        PerRequestActivePorts*  pPerRequestPorts,
        IPEBandwidth*           pBandwidth);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsMultiCameraUsecase
    ///
    /// @brief  check if we are running in multicamera mode
    ///
    /// @return TRUE indicateds if in multicamera mode
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL IsMultiCameraUsecase();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// UpdateNumberofPassesonDimension
    ///
    /// @brief  Update the number of passes based on dimension
    ///
    /// @param  parentNodeID  Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    ///
    /// @return CamxResult Indicates if update is a failure
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult UpdateNumberofPassesonDimension(
        UINT parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetOEMStatsConfig
    ///
    /// @brief  Returns OEM's custom stats configuration
    ///
    /// @param  pInputData    Pointer to the ISP input data for setting updates
    /// @param  parentNodeID  Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    ///
    /// @return CamxResultSuccess if success
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetOEMStatsConfig(
        ISPInputData* pInputData,
        UINT          parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetOEMIQConfig
    ///
    /// @brief  Returns OEM's custom IQ configuration
    ///
    /// @param  pInputData    Pointer to the ISP input data for setting updates
    /// @param  parentNodeID  Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    ///
    /// @return CamxResultSuccess if success
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetOEMIQConfig(
        ISPInputData* pInputData,
        UINT          parentNodeID);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetStaticMetadata
    ///
    /// @brief  Get all static information from HAL metadata tags for all IPE modules
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID GetStaticMetadata();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetCorrespondingOutputReferencePort
    ///
    /// @brief  Helper method to find the corresponding reference output port for an input port
    ///
    /// @param  pPerRequestPorts    Request specific data
    /// @param  inputPortId         InputportId to check
    ///
    /// @return pointerto the outputport
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    PerRequestOutputPortInfo* GetCorrespondingOutputReferencePort(
        PerRequestActivePorts*   pPerRequestPorts,
        UINT inputPortId);


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsReferenceOutputPort
    ///
    /// @brief  Helper method to determine if the output port is a reference port.
    ///
    /// @param  outputPortId OutputportId to check
    ///
    /// @return TRUE if the output port is a reference port, FALSE otherwise
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CAMX_INLINE BOOL IsReferenceOutputPort(
        UINT outputPortId
    ) const
    {
        BOOL isReferencePort = FALSE;

        switch (outputPortId)
        {
            case IPEOutputPortFullRef:
            case IPEOutputPortDS4Ref:
            case IPEOutputPortDS16Ref:
            case IPEOutputPortDS64Ref:
                isReferencePort = TRUE;
                break;

            default:
                break;
        }

        return isReferencePort;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsReferenceInputPort
    ///
    /// @brief  Helper method to determine if the input port is a reference port.
    ///
    /// @param  inputPortId InputportId to check
    ///
    /// @return TRUE if the input port is a reference port, FALSE otherwise
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CAMX_INLINE BOOL IsReferenceInputPort(
        UINT inputPortId
    ) const
    {
        BOOL isReferencePort = FALSE;

        switch (inputPortId)
        {
            case IPEInputPortFullRef:
            case IPEInputPortDS4Ref:
            case IPEInputPortDS16Ref:
            case IPEInputPortDS64Ref:
                isReferencePort = TRUE;
                break;

            default:
                break;
        }

        return isReferencePort;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// IsValidDimension
    ///
    /// @brief  Check if input param is between min and max of IPE
    ///
    /// @param  pZoomWindow Dimension to check
    ///
    /// @return false if dime is lesser the min or gretear them max
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL IsValidDimension(
        IpeZoomWindow* pZoomWindow);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetEISMarginPixels
    ///
    /// @brief  Get EIS margin in pixels
    ///
     /// @return CamxResultSuccess if successful.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetEISMarginPixels();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetEISMargin
    ///
    /// @brief  Get EIS requested margin
    ///
    /// @return CamxResultSuccess if successful.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetEISMargin();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetStabilizationMargins
    ///
    /// @brief  Get the stabilization margins depending on the Image Stabilization type for this node
    ///
    /// @return CamxResultSuccess if success
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CamxResult GetStabilizationMargins();

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SetScaleRatios
    ///
    /// @brief  Set Scale Ratios for IPE triggers
    ///
    /// @param  pInputData        Pointer to the ISP input data for setting updates
    /// @param  parentNodeID      Parent Node ID: IFE, JPEG, IPE, BPS, FDhw etc
    /// @param  pCropInfo         Pointer to the IFE Crop Information
    /// @param  pIFEScalerOutput  Pointer to the IFE Scaler Output
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL SetScaleRatios(
        ISPInputData*     pInputData,
        UINT              parentNodeID,
        IFECropInfo*      pCropInfo,
        IFEScalerOutput*  pIFEScalerOutput);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CheckIsIPERealtime
    ///
    /// @brief  Returns true if IPE is part of a realtime stream
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL CheckIsIPERealtime();


    static const UINT MaxIPEIQModule   = 30;    ///< Max Number of IQ Modules
    static const UINT MaxScratchBuffer = 1;     ///< Max Number of Scratch/Internal Buffers

    UINT                    m_IPECmdBlobCount;                              ///< Based on req queue depth or for MFNR few bufs
    CmdBufferManager*       m_pIQPacketManager;                             ///< IQ Packet buffer manager
    CmdBufferManager*       m_pIPECmdBufferManager[IPECmdBufferMaxIds];     ///< Array Cmd buffer managers for IPE node
    CSLBufferInfo*          m_pScratchMemoryBuffer[MaxScratchBuffer];       ///< Pointer to array of scratch buffers
    INT32                   m_deviceIndex;                                  ///< ICP device index
    CSLDeviceHandle         m_hDevice;                                      ///< IPE device handle
    ISPIQModule*            m_pEnabledIPEIQModule[MaxIPEIQModule];          ///< List of IQ Modules
    CSLVersion              m_version;                                      ///< IPE Hardware Revision
    IPECapabilityInfo       m_capability;                                   ///< IPE Capability Configuration
    UINT                    m_numIPEIQModulesEnabled;                       ///< Number of IPE IQ Modules
    UINT                    m_firmwareScratchMemSize;                       ///< Maximum Size of scratch buffer needed by FW
    UINT                    m_numScratchBuffers;                            ///< Number of Scratch/Internal buffers
    UINT                    m_maxCmdBufferSizeBytes[IPECmdBufferMaxIds];    ///< Array Cmd buffer managers for IPE node
    UINT32                  m_preLTMLUTOffset[ProgramIndexMaxPreLTM];       ///< Array of offsets within DMI Header cmd buffer
    UINT32                  m_postLTMLUTOffset[ProgramIndexMaxPostLTM];     ///< Array of offsets within DMI Header cmd buffer
    UINT32                  m_preLTMLUTCount[ProgramIndexMaxPreLTM];        ///< Array of number of Look up tables in IQ blocks
    UINT32                  m_postLTMLUTCount[ProgramIndexMaxPostLTM];      ///< Array of number of Look up tables in IQ blocks
    SL_HANDLE               m_hStripingLib;                                 ///< Stripe library handle
    static FrameBuffers     s_frameBufferOffset[IPEMaxSupportedBatchSize][IPE_IO_IMAGES_MAX];   ///< Offset to buffer ptr base
    UINT32                  m_ANRPassOffset[PASS_NAME_MAX];                 ///< Array of offsets for anr passes in cmd buffer
    UINT32                  m_ANRSinglePassCmdBufferSize;                   ///< Size of single ANR pass cmd buffer
    BOOL                    m_isStatsNodeAvailable;                         ///< True when stats node available and enabled
    IPETuningMetadata*      m_pTuningMetadata;                              ///< Metadata for tuning support
    BOOL                    m_OEMStatsConfig;                               ///< Variable to track OEM controlled stats
    UINT32                  m_fullInputWidth;                               ///< Width of the full input image in pixels.
    UINT32                  m_fullInputHeight;                              ///< Height of the full input image in pixels.
    INT32                   m_fullOutputWidth;                              ///< Width of the full output image in pixels.
    INT32                   m_fullOutputHeight;                             ///< Height of the full output image in pix
    IPEInstanceProperty     m_instanceProperty;                             ///< IPE Node Instance Property
    IFECropInfo             m_previousCropInfo;                             ///< Last crop info from IFE
    ISPHALTagsData          m_HALTagsData;                                  ///< Keep all input coming from tags
    // Region                  m_previousHALZoomCropRegion;                   ///< Last HAL zoom crop region
    UINT                    m_FPS;                                          ///< FPS requested
    UINT                    m_maxBatchSize;                                 ///< Number of frames in a batch
    UINT32                  m_ICALUTOffset[ProgramIndexICAMax];             ///< Number of LUTs for each instance of ICA
    UINT                    m_ICALUTCount[ProgramIndexICAMax];              ///< LUT Count for ICA1
    UINT32                  m_TFPassOffset[PASS_NAME_MAX];                  ///< Array of offsets for tf passes in cmd buffer
    UINT32                  m_TFSinglePassCmdBufferSize;                    ///< Size of single TF pass cmd buffer
    UINT32                  m_numOutputRefPorts;                            ///< number of output reference ports enabled in IPE
    BOOL                    m_OEMICASettingEnable;                          ///< indicator for OEM ICA Setting Mode
    BOOL                    m_OEMIQSettingEnable;                           ///< indicator for OEM IQ Setting Mode
    BOOL                    m_OEMStatsSettingEnable;                        ///< indicator for OEM Stats Setting Mode
    UINT                    m_IPEICATAGLocation[IPEProperties];             ///< ICA Tags
    UINT                    m_MFNRTotalNumFramesTAGLocation;                ///< MFNR Total number frames
    UINT                    m_numPasses;                                    ///< Number of IPE passes
    ISPInternalData         m_ISPData;                                      ///< Data Calculated by IQ Modules
    FLOAT                   m_prevFOVC;                                     ///< Last value of FOV compantation
    BOOL                    m_enableIPEHangDump;                            ///<  IPE hangdump
    static UINT64           s_debugDataRequestId;                           ///< Debug data requestID tracking
    static DebugDataWriter* s_pDebugDataWriter;                             ///< Pointer to the debug data pointer
    static UINT32           s_debugDataWriterCounter;                       ///< Debug data intance tracker
    BOOL                    m_resetReferenceInput;                          ///< Reset input reference ports
    StabilizationMargin     m_stabilizationMargin;                          ///< ICA margin Dimensions
    MarginRequest           m_EISMarginRequest;                             ///< EIS requested margin as a percentage
    BOOL                    m_FOVCEnabled;                                  ///< FOVC feature enabled or not
    ChiTuningModeParameter  m_tuningData;                                   ///< Tuning data
    BOOL                    m_nodePropDisableZoomCrop;                      ///< Disables the zoom crop so IPE only outputs
    BOOL                    m_realTimeIPE;                                  ///< IPE needs to run realtime
    BOOL                    m_compressiononOutput;                          ///< Compression enabled on output
    PropertyISPADRCInfo     m_adrcInfo;                                     ///< Adrc Info get from IFE/BPS
};

CAMX_NAMESPACE_END

#endif // CAMXIPENODE_H
